package com.modelo.dao.proveedordocumento;

import java.util.List;

import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Repository;

import com.modelo.dao.comun.HibernateBaseDAO;
import com.modelo.entity.ProveedorDocumento;

@Repository
public class ProveedorDocumentoDAO extends HibernateBaseDAO<ProveedorDocumento> implements
		IProveedorDocumentoDAO {
	public static final String ID_ENTIDAD = "idEntidad";

	private static final Logger log = LoggerFactory.getLogger(ProveedorDocumentoDAO.class);
	public static final String OBSERVACIONES = "observaciones";
	public static final String VISTO = "visto";

	public static ProveedorDocumentoDAO getFromApplicationContext(ApplicationContext ctx) {
		return (ProveedorDocumentoDAO) ctx.getBean("ProveedorDocumentoDAO");
	}

	@Autowired
	public ProveedorDocumentoDAO(SessionFactory sessionFactory) {
		super(sessionFactory);
	}

	public List<ProveedorDocumento> findByExample(ProveedorDocumento instance) {
		log.debug("finding ProveedorDocumento instance by example");
		try {
			List<ProveedorDocumento> results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: " + results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List<ProveedorDocumento> findByIdEntidad(Object idEntidad) {
		return findByProperty(ID_ENTIDAD, idEntidad);
	}

	public List<ProveedorDocumento> findByObservaciones(Object observaciones) {
		return findByProperty(OBSERVACIONES, observaciones);
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding ProveedorDocumento instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from ProveedorDocumento as model where model." + propertyName
					+ "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List<ProveedorDocumento> findByVisto(Object visto) {
		return findByProperty(VISTO, visto);
	}

	@Override
	protected void initDao() {

	}
}